<?php

namespace App\Transformers;

use App\Models\Tag;
use League\Fractal\TransformerAbstract;

class TagTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['articles'];

    public function transform(Tag $tag)
    {
        return $tag->attributesToArray();
    }

    public function includeArticles(Tag $tag)
    {
        if (!$tag->articles) {
            return $this->null();
        }

        return $this->collection($tag->articles, new ArticleTransformer());
    }
}